from flask import jsonify
from .. import utils
from . import api


@api.route('/get_auth_status/<sn>/')
def get_auth_status(sn):
	r=utils.exec_command(sn, 'curl -s http://115.29.151.181/webtool/wifi/get_auth_status.sh | sh')
	return jsonify(r)

@api.route('/get_showflow/<sn>/')
def get_showflow(sn):
	r=utils.exec_command(sn, 'fcctl showflow all')
	return jsonify(r)

@api.route('/get_dhcp_status/<sn>/')
def get_dhcp_status(sn):
	r=utils.exec_command(sn, 'cat /tmp/dhcp.leases')
	return jsonify(r)

@api.route('/get_arp/<sn>/')
def get_arp(sn):
	r=utils.exec_command(sn, 'cat /proc/net/arp')
	return jsonify(r)

@api.route('/get_qos/<sn>/')
def get_qos(sn):
	r=utils.exec_command(sn, 'curl -s http://115.29.151.181/webtool/wifi/get_qos.sh | sh')
	return jsonify(r)

@api.route('/get_urlfilter/<sn>/')
def get_urlfilter(sn):
	r=utils.exec_command(sn, 'curl -s http://115.29.151.181/webtool/wifi/get_urlfilter.sh | sh')
	return jsonify(r)

@api.route('/get_local_log/<sn>/')
def get_local_log(sn):
	r=utils.exec_command(sn, 'tail -30 /var/log/nginx/localweb.log')
	return jsonify(r)

@api.route('/get_access_log/<sn>/')
def get_access_log(sn):
	r=utils.exec_command(sn, 'tail -30 /var/log/nginx/access.log')
	return jsonify(r)

#Operate WIFI
@api.route('/opt_url_filter/<sn>/')
def opt_url_filter(sn):
	r=utils.exec_command(sn, 'curl -s http://wsg.f3322.net:9080/airmedia_info/config/urlfilter_on_off.sh | sh')
	return jsonify(r)

@api.route('/opt_itc_limit/<sn>/')
def opt_itc_limit(sn):
	r=utils.exec_command(sn, 'curl -s http://wsg.f3322.net:9080/airmedia_info/config/itc_on_off.sh | sh')
	return jsonify(r)

@api.route('/opt_repair_ssd/<sn>/')	#40
def opt_repair_ssd(sn):
	r=utils.exec_command(sn, 'curl -s http://wsg.f3322.net:9080/airmedia_info/RepairSda.sh | sh')
	return jsonify(r)

@api.route('/opt_tiny_web/<sn>/')
def opt_tiny_web(sn):
	r=utils.exec_command(sn, 'curl -s http://115.29.151.181/ssd_repair/fix_sda5_web.sh | sh')
	return jsonify(r)

@api.route('/opt_web_file/<sn>/')
def opt_web_file(sn):
	r=utils.exec_command(sn, 'curl -s http://wsg.f3322.net:9080/airmedia_info/config/update_web_file.sh | sh')
	return jsonify(r)

@api.route('/opt_php_config/<sn>/')
def opt_php_config(sn):
	r=utils.exec_command(sn, '')
	return jsonify(r)

@api.route('/opt_update_init/<sn>/')	#40
def opt_update_init(sn):
	r=utils.exec_command(sn, '')
	return jsonify(r)

@api.route('/opt_update_host/<sn>/')
def opt_update_host(sn):
	r=utils.exec_command(sn, '')
	return jsonify(r)